Often when you are dealing with information you will want to hold a collection of different things about a particular item. For example, consider if the Nat. West. Bank commissioned you to write a customer database system. (It is in fact rather unlikely that this will happen - such systems are written in COBOL, not C!). Like any good programmer who has been on my course you would start by doing the following:

  1. Establish precisely the specification, i.e. get in written form exactly what they expect your system to do.

  2. Negotiate an extortionate fee.

  3. Consider how you will go about storing the data.

From your specification you know that the program must hold the following:

  • customer name - 30 character string

  • customer address - 60 character string

  • account number - integer value

  • account balance - integer value

  • overdraft limit - integer value

The Nat. West. have told you that they will only be putting up to 50 people into your database so, after a while you come up with the C code on the right hand side.

What you have is an array for each single piece of data we want to store about a particular customer. If we were talking about a database (which is actually what we are writing), the lump of data for each customer would be called a record and an individual part of that lump, for example the overdraft value, would be called a field. In our program we are working on the basis that balance[1] holds the balance of the first customer in our database, overdraft [1] holds the overdraft of the first customer, and so on.

This is all very well, and you could get a database system working with this data structure. However it would me much nicer to be able to lump your record together in a more definite way.

 



/* declare an array for each item   */
/* stored. Note that the name and   */
/* address arrays are 2 dimensional */
/* (i.e. a table) we store a row of */
/* name characters for each bank    */
/* record. We do the same with      */
/* addresses                        */

char name [30] [50] ;
char address [60] [50] ;
int account [50] ;
int balance [50] ;
int overdraft [50] ;